{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python \t\t3.6\n",
      "Tensorflow \t1.0.0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Keras \t\t2.0.3\n"
     ]
    }
   ],
   "source": [
    "import sys; print('Python \\t\\t{0[0]}.{0[1]}'.format(sys.version_info))\n",
    "import tensorflow as tf; print('Tensorflow \\t{}'.format(tf.__version__))\n",
    "import keras; print('Keras \\t\\t{}'.format(keras.__version__))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline \n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting ../mnist-data/train-images-idx3-ubyte.gz\n",
      "Extracting ../mnist-data/train-labels-idx1-ubyte.gz\n",
      "Extracting ../mnist-data/t10k-images-idx3-ubyte.gz\n",
      "Extracting ../mnist-data/t10k-labels-idx1-ubyte.gz\n"
     ]
    }
   ],
   "source": [
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "mnist = input_data.read_data_sets(\"../mnist-data/\", one_hot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(55000, 784)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mnist.train.images.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA2oAAABpCAYAAABLV9A4A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IiIiIJoxk1qdUpp5wCwGOPPVbnzxljavSNGzfO\ntV944QUADj30UNfXsWPHEEMsWQsWLADgBz/4geu77bbbAPjZz35WkDEl0X//+1/XvuSSS4D0Y9Pb\ncNYd5506dcrT6ERERBpu9erVrv3vf/+71p/zX89uueUWAHr06OH6dt11VwD22muv0EOUQDSjJiIi\nIiIikjD6oCYiIiIiIpIwWvooaexyR6h7yeNuu+3m2n379gXggw8+cH2TJqX2QFy0aBEADzzwgOsb\nM2ZM7oMtYW+99RYAm22W+q6lffv2hRpOYn388ceufffddwPQrFkz11dRUeHakydPBmDkyJF5Gl3y\n/etf/3LtE088EYDKysog1/33v//dtbt16wZAhw4dglx3U2aP0/79+7u+22+/HUgv4uQf503ZihUr\nABg0aJDrO/DAAwEYPny46+vcuXPQ2/3Pf/7j2v/85z+B1GshwBZbbBH09qR0TZkyxbXt43/69Omu\nb+HChbX+rn96hH3u/uabb2r83MaNG3McpcRFM2oiIiIiIiIJoxk1AVIzC08++WSNy/wTT+1MWevW\nrV3ftttuC8D69etd3/777+/ab7/9NgCfffZZwBGXttmzZwOp7CE14yGwcuVKAIYOHVrgkRS3qVOn\nunamb2Fz4c+633vvvQA8/PDDQW+jqfCfO/1ZM8sWEBo2bJjr22qrreIfWIH4hRR23313IH2Gq127\ndkD4WTT/dnr16uX6Vq1aBaTP0Hft2jX4bRfSmjVrALjssstc39y5c4FUwTDQTGJjLF682LX/9Kc/\nATB+/HjXZ7dFAoiiqEHX/f777+c4Oik0zaiJiIiIiIgkjD6oiYiIiIiIJEzRLH2cOHGia9uiADvt\ntJPra9GiBQBnnHGG6/vud78LQJcuXfIxxKK2fPlyIH1a3S559Jc/lZWV1XodY8eOde358+fXuLxf\nv345j7OUzZkzx7Vt8YAhQ4YUajiJY/eRA3jqqacAePPNN7P+/RkzZgDpjwG7t8whhxwSYohFY8OG\nDQA888wzsd2Gv4fdzTffDKTve7fNNtvEdtvFxharAFi2bFmNy0877TQg9TrYVNklhn7hELss9Kc/\n/an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cyxjxvjFlY9f8dCjA2ZRp+bMo0/NiKMlNIbq7KNJZxKdPw41Km4celTOMZW1HmqkzDS1SmURTl\n5T+gGbAY+D7QHHgb6J6v289x7GVAr6p2S2AB0B24Abisqv8y4A95HpcyVabKtARzVabKVJkqU2Wq\nXJVp0880nzNq+wGLoij6IIqi9cDDwIA83n6jRVG0PIqif1W1vwTmA+3ZNP4JVT82ATg+z0NTpuEp\n0/CKNlPF+aheAAABtElEQVRIbK7KNDxlGp4yDU+ZxqNoc1Wm4SUp03x+UGsPfOT9e2lVX1ExxnQG\negKvA+2iKFpeddEnQLs8D0eZhqdMw2sSmUKiclWm4SnT8JRpeMo0Hk0iV2UaXqEzVTGRBjDGbAs8\nDoyKomiNf1m0aR5Uex00kDINT5nGQ7mGp0zDU6bhKdPwlGl4yjS8JGSazw9qy4AO3r93ruorCsaY\nLdj0x3owiqInqro/NcaUVV1eBqzI87CUaXjKNLyizhQSmasyDU+ZhqdMw1Om8SjqXJVpeEnJNJ8f\n1N4EuhpjvmeMaQ6cCkzK4+03mjHGAH8G5kdRdLN30SRgaFV7KPB0noemTMNTpuEVbaaQ2FyVaXjK\nNDxlGp4yjUfR5qpMw0tUpqGqkmTzH3AMmyqnLAZ+lc/bznHcvdk0vfkOMLvqv2OAHYFpwELgBaBV\nAcamTJWpMi3BXJWpMlWmylSZKldl2rQzNVUDEhERERERkYRQMREREREREZGE0Qc1ERERERGRhNEH\nNRERERERkYTRBzUREREREZGE0Qc1ERERERGRhNEHNRERERERkYTRBzUREREREZGE+X+IUBJIT7+7\nfwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x11495f4e0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15,5))\n",
    "for i in list(range(10)):\n",
    "    plt.subplot(1, 10, i+1)\n",
    "    pixels = mnist.test.images[i]\n",
    "    pixels = pixels.reshape((28, 28))\n",
    "    plt.imshow(pixels, cmap='gray_r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Activation\n",
    "from keras.layers import Dropout, Flatten, Reshape\n",
    "from keras.layers import Conv2D, MaxPooling2D\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model = Sequential()\n",
    "model.add(Reshape((28,28,1), input_shape=(784,)))\n",
    "\n",
    "model.add(Conv2D(32, (3, 3), padding='same', activation='relu'))\n",
    "model.add(Conv2D(32, (3, 3), padding='same', activation='relu'))\n",
    "model.add(MaxPooling2D((2,2))) \n",
    "\n",
    "model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))\n",
    "model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))\n",
    "model.add(MaxPooling2D((2,2)))\n",
    "\n",
    "model.add(Flatten())\n",
    "model.add(Dropout(0.5))\n",
    "\n",
    "model.add(Dense(256, activation='relu'))\n",
    "model.add(Dropout(0.25))\n",
    "\n",
    "model.add(Dense(10, activation='softmax'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18432"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "32*3*3*64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reshape_1 (None, 28, 28, 1) []\n",
      "conv2d_1 (None, 28, 28, 32) [288, 32]\n",
      "conv2d_2 (None, 28, 28, 32) [9216, 32]\n",
      "max_pooling2d_1 (None, 14, 14, 32) []\n",
      "conv2d_3 (None, 14, 14, 64) [18432, 64]\n",
      "conv2d_4 (None, 14, 14, 64) [36864, 64]\n",
      "max_pooling2d_2 (None, 7, 7, 64) []\n",
      "flatten_1 (None, 3136) []\n",
      "dropout_1 (None, 3136) []\n",
      "dense_1 (None, 256) [802816, 256]\n",
      "dropout_2 (None, 256) []\n",
      "dense_2 (None, 10) [2560, 10]\n"
     ]
    }
   ],
   "source": [
    "from  functools import reduce\n",
    "\n",
    "for l in model.layers:\n",
    "    print(l.name, l.output_shape, [reduce(lambda x, y: x*y, w.shape) for w in l.get_weights()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=[\"accuracy\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 55000 samples, validate on 10000 samples\n",
      "Epoch 1/5\n",
      "55000/55000 [==============================] - 200s - loss: 0.2615 - acc: 0.9163 - val_loss: 0.0502 - val_acc: 0.9837\n",
      "Epoch 2/5\n",
      "55000/55000 [==============================] - 196s - loss: 0.0750 - acc: 0.9769 - val_loss: 0.0323 - val_acc: 0.9889\n",
      "Epoch 3/5\n",
      "55000/55000 [==============================] - 189s - loss: 0.0512 - acc: 0.9843 - val_loss: 0.0240 - val_acc: 0.9917\n",
      "Epoch 4/5\n",
      "55000/55000 [==============================] - 189s - loss: 0.0423 - acc: 0.9872 - val_loss: 0.0208 - val_acc: 0.9924\n",
      "Epoch 5/5\n",
      "55000/55000 [==============================] - 190s - loss: 0.0340 - acc: 0.9885 - val_loss: 0.0257 - val_acc: 0.9911\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x11ef9ad30>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from keras.callbacks import TensorBoard, BaseLogger\n",
    "\n",
    "tb = TensorBoard(log_dir='./tensorboard/keras', histogram_freq=0, write_graph=True, write_images=False)\n",
    "bl = BaseLogger()\n",
    "\n",
    "model.fit(mnist.train.images, mnist.train.labels,\n",
    "          batch_size=250, epochs=5, verbose=1, callbacks=[tb,bl],\n",
    "          validation_data=(mnist.test.images, mnist.test.labels))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Test score: 0.0256542290048\n",
      "Test accuracy: 0.9911\n"
     ]
    }
   ],
   "source": [
    "score = model.evaluate(mnist.test.images, mnist.test.labels,verbose=0)\n",
    "print('Test score:', score[0])\n",
    "print('Test accuracy:', score[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: 2.6677342e-06,\n",
       " 1: 6.8658895e-10,\n",
       " 2: 3.9473185e-09,\n",
       " 3: 7.6411266e-10,\n",
       " 4: 2.3078299e-07,\n",
       " 5: 5.4647614e-07,\n",
       " 6: 0.99999607,\n",
       " 7: 1.2507323e-09,\n",
       " 8: 5.2479925e-07,\n",
       " 9: 2.823896e-09}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# test item #100 is a six\n",
    "pixels = mnist.test.images[100]\n",
    "result = model.predict(np.array([pixels]))\n",
    "dict(zip(range(10), result[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def test_render(pixels, result, truth):\n",
    "    #pixels, result and truth are np vectors\n",
    "    plt.figure(figsize=(10,5))\n",
    "    plt.subplot(1, 2, 1)\n",
    "    pixels = pixels.reshape((28, 28))\n",
    "    plt.imshow(pixels, cmap='gray_r')\n",
    "\n",
    "    plt.subplot(1, 2, 2)\n",
    "    \n",
    "    #index, witdh\n",
    "    ind = np.arange(len(result))\n",
    "    width = 0.4\n",
    "\n",
    "    plt.barh(ind,result, width, color='gray')\n",
    "    plt.barh(ind+width,truth,width, color='green')\n",
    "    plt.yticks(ind+width, range(10))\n",
    "    plt.margins(y=0)\n",
    "\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlMAAAEyCAYAAADeAVWKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGfBJREFUeJzt3X+QXXV9xvHnMYEKhAqRJRN+pKEa0TStwV5TLEqDqBNS\nhqh1lMyAxIks44ASim2j7UzU2sE2gtoZtCxCoSqxqIAZGxEGoUAFyi4ESAgIRtDEmF0EDOiUmPDp\nH/cEliW752y+d+85J+f9mtnZe8/9JPfZmwAP58f3OCIEAACAPfOKsgMAAADUGWUKAAAgAWUKAAAg\nAWUKAAAgAWUKAAAgAWUKAAAgAWUKAAAgAWUKAAAgAWUKAAAgweSyAwBAHRxyyCExc+bMsmMA6KKB\ngYEnIqInb44yBQAFzJw5U/39/WXHANBFth8vMsdhPgCNZftc2+tsr7e9rOw8AOqJMgWgkWzPkXSm\npHmS3ijpZNuvLTcVgDqiTAFoqjdIuisifhsROyT9t6T3lpwJQA1RpgA01TpJb7P9atv7S1oo6ciS\nMwGoIU5AB9BIEbHB9j9LukHSbyStlbRz+IztXkm9kjRjxoyuZwRQD+yZAtBYEXFZRPxpRBwv6SlJ\nPx7xel9EtCKi1dOTe3U0gIZizxSAxrJ9aEQM2p6h9vlSx5adCUD9dLVMsegd0DxFF70ryXdsv1rS\n7ySdHRFPlx0IQP0klSnbCyR9SdIkSV+NiM+NNc+id0DzFF30rgwR8bayMwCovz0+Z8r2JEkXSzpJ\n0mxJi23P7lQwAACAOkg5AX2epEcjYmNEbJf0TUmLOhMLAACgHlLK1OGSfj7s+aZsGwAAQGNM+NII\ntntt99vuHxoamui3AwAA6KqUMrVZL10t+Ihs20uwTgsAANibpZSpuyXNsn2U7X0lnSppdWdiAQAA\n1MMeL40QETtsnyPpB2ov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8tfcM3mr7jyPi6VJTFbdY0hURcaHtt0j6mu052aK/jcSe\nKQB4UZG7M7wwY3uy2oc5ftWVdPkK3V3C9jsk/b2kUyLiuS5lKyrvZzhQ0hxJt9h+TNKxklZX6CT0\nIn8GmyStjojfRcRPJf1Y7XJVBUXyL1V7LT1FxB2SXqn2GoF10fG7sFCmAOBFRe7OMHyF+/dJ+mFU\nZ8G+3Py2j5F0idpFqkrn6uwy5s8QEb+OiEMiYmZEzFT7vK9TIqK/nLgvU+Tv0HVq75WS7UPUPuy3\nsZshx1Ak/88knShJtt+gdpka6mrKNKslfTC7qu9YSb9OXaSYw3wAkImIHbbPkfQDvXh3hvW2PyOp\nPyJWq307nq/ZflTtk1xPLS/xSxXMv1LSFEnfys6b/1lEnFJa6BEK/gyVVTD/DyS9y/aDknZK+puI\nqMTezYL5z5d0qe3z1D4ZfUmF/ofiJXfUyM7rWiFpH0mKiH9T+zyvhZIelfRbSR9Kfs8K/fwAAAC1\nw2E+AACABJQpAACABJQpAACABJQpAACABJQpAACABJQpAACABJQpAACABP8PqvGJisNdHREAAAAA\nSUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x11e6003c8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import random\n",
    "i = random.randint(0,mnist.test.images.shape[0])\n",
    "\n",
    "pixels = mnist.test.images[i]\n",
    "truth  = mnist.test.labels[i]\n",
    "result = model.predict_on_batch(np.array([pixels]))[0]\n",
    "test_render(pixels, result, truth)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### What went wrong?\n",
    "pixels = mnist.test.images\n",
    "result = model.predict_on_batch([pixels])\n",
    "truth = mnist.test.labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Incorrect predictions: 89\n"
     ]
    }
   ],
   "source": [
    "acc = result.argmax(axis=1) == truth.argmax(axis=1)\n",
    "incorrect = np.argwhere(acc==False).flatten()\n",
    "\n",
    "print(\"Incorrect predictions: {}\".format(len(incorrect)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABIEAAABdCAYAAAAyhXaGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XecXFX5x/HPhYCUgFRDCAQEQpEWICECghEB6aj0IgSQ\npmiCIISOdASkSgfpNUqPdEIXCb3EBAihhBClSAjCL0Du74/sd87M7Lmzs7szs1O+79crr93MzM6e\nffbMnbv3POd5kjRNMTMzMzMzMzOz5jZbTw/AzMzMzMzMzMyqzxeBzMzMzMzMzMxagC8CmZmZmZmZ\nmZm1AF8EMjMzMzMzMzNrAb4IZGZmZmZmZmbWAnwRyMzMzMzMzMysBfgikJmZmZmZmZlZC+jWRaAk\nSTZNkmR8kiRvJEkyslKDagaOTZzjks2xiXNcsjk2cY5LNscmznHJ5tjEOS7ZHJs4xyXOccnm2MQ5\nLt2XpGnatS9MktmBCcDGwHvAM8DOaZq+VrnhNSbHJs5xyebYxDku2RybOMclm2MT57hkc2ziHJds\njk2c4xLnuGRzbOIcl8rozkWgdYDj0jT9Sdv/DwdI0/SUrK9ZZJFF0qWXXrpL36+RTJ8+nfHjx3+V\npumc0HFsHBfPGc+ZOM+ZbK+//jrTpk27r9xjcKvExXMmm+dMnOdMNs+ZOM+ZbJ4zcZ4zcdOnT2fi\nxInMmDEjAccln+dMnOdMac8+++yHaZou2tHjenXje/QD3s37/3vAkOIHJUmyL7AvQP/+/Rk7dmw3\nvmVjGDVqFNtvv/2neTe1i43jAnjO5HjOxHnOZFt22WWZNm1ayWNwK8bFcyab50yc50w2z5k4z5ls\nnjNxnjNxo0aNYv/998+/yXFp4zkT5zlTWpIkb5fzuKoXhk7T9J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KtIP/Yst122wGFxfoBDjnkEABOP/302g2sim688UYAdt11VyDMA9Fcyb99/vnnB2DkyJEArLfe\negAMGTIEgG9961tVHLHVm88++wyA888/v+D2++67L/f5P/7xDyBsYTj44IMBWHjhhWsxRGsQkydP\nzn1+5JFHAmEbmHz88ccAHHbYYYC3gzW7/fffH4AXX3wRKDx/yfLee+8BsNtuuwHhHHCVVVapxhCr\nQudm++67LwBzzz03AP379wfCVu0nnngCgH/+858A9O3bF4D1118/91zLLrtsDUZc/zbeeGMgbH8H\nWGaZZQB48803e2RMtaDmU/r5//WvfwHw/e9/v+B2nd8CzDnnnLUcYlmcCWRmZmZmZmZm1gIaNhPo\nV7/6FQBTp04FQpGyv//970AorGmzKFPqtddeA+Dtt9/O3adVAGVRXXvttTUeXXX897//BeBnP/sZ\nAI888kjB/d/5zneAsDqm4qsqjA0hNrqto5UTre7r/q233jp3X6NkWGllWasiKmybn7lQ/PPrdbjD\nDjsA8PLLL1d9nPXkoosuanfbUUcdBYQVg1NOOQVo7kwgZYudfPLJAEyZMiV33/PPPw+EuaOix7vs\nsksth1h1zz77LBAKaRZnWsYoA+jwww+v3sDq3KeffgrAlltu2e6+YcOGAaERRLMaP348AGuvvTYA\n06dPL7g/dgw+7bTTgJA1pNfegQceWN3BWkM45phjcp9fddVVJR+rlftXXnkFaKwsj84aN25c7vM1\n11wTgFVXXRUIWXazzdZc6+TaAfDGG29E79cxZZ555sndNmPGDCCcB+r9TZkPjTRHlKWhgtiDBhV2\nXdfPNt988wGw0UYbAbDnnnsCMGLEiNxjzzrrrOoOts7p/PbBBx9sd18r7MD5z3/+A4S/CUV/Z44Z\nMwaATz75JHdfPWa7N9cRzszMzMzMzMzMoho2E+iWW24B4JtvvgHg5ptvBpwBlEWZCqrvErPIIosA\njX8VV1do99hjDwAeffRRoH32ih6nq/vnnXceAF988UW75/z888+BkF1UbiaQsqug/jOBtAqmFR69\ntkSZDRBits8++wCw0047Ac29B7gU7THPp7ajl156aa2HUzN6Dd10001A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W6CNQPeDfv/+9RmV9qj0mSZGlgDeDptpsOTJLkpSRJrkiSZMFOPFVTxcZxyebYxDku2RybOMcl\nm2MT57hkc2ziHJdsjk2c45LNsYlzXOIqGBdwbKJcGLoLkiTpDfwVGJGm6TTgQmBZYCAwBTizB4fX\nYxyXbI5NnOOSzbGJc1yyOTZxjks2xybOccnm2MQ5LtkcmzjHJc5xyVbJ2NTqItBkYMm8/y/RdlvD\nSZJkDmYF/7o0Tf8GkKbp1DRNv0nTdCZwKbPSzsrVFLFxXLI5NnGOSzbHJs5xyebYxDku2RybOMcl\nm2MT57hkc2ziHJe4KsQFHJuoWl0EegYYkCTJd5MkmRPYCbijRt+7YpIkSYDLgXFpmv4p7/a+eQ/7\nGfBKJ5624WPjuGRzbOIcl2yOTZzjks2xiXNcsjk2cY5LNscmznHJ5tjEOS5xVYoLODZRvSo3vGxp\nmn6dJMmBwL3MqtB9RZqmr9bie1fYesAvgJeTJHmh7bYjgJ2TJBkIpMAkYL9yn7BJYuO4ZHNs4hyX\nbI5NnOOSzbGJc1yyOTZxjks2xybOccnm2MQ5LnEVjws4NlmSdFarMTMzMzMzMzMza2IuDG1mZmZm\nZmZm1gJ8EcjMzMzMzMzMrAX4IpCZmZmZmZmZWQvwRSAzMzMzMzMzsxbgi0BmZmZmZmZmZi3AF4HM\nzMzMzMzMzFqALwKZmZmZmZmZmbUAXwQyMzMzMzMzM2sB/w8o1P7+1c16UAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1153a89b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(20,5))\n",
    "plt_idx = 1\n",
    "for i in list(incorrect[:16]):\n",
    "    plt.subplot(1, 16, plt_idx)\n",
    "    pixels = mnist.test.images[i]\n",
    "    pixels = pixels.reshape((28, 28))\n",
    "    plt.imshow(pixels, cmap='gray_r')\n",
    "    plt_idx += 1\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlMAAAEyCAYAAADeAVWKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGvZJREFUeJzt3X+QXXWd5vHnMcACCQ4xNDEJZBo0YxFwCWzD4pJBNMYi\naJFxl0oRSwanqGmtglmYVVfGXStm1y0dGHFmqwANwgKzgusojBFBoQA3sIWs3ZAlTQJjDEGTTkiD\nID+UgYTP/nFPoG278z3J9/Y95+S+X1Vdfe+5n7736ZsAD+ee8z2OCAEAAGDfvKXqAAAAAE1GmQIA\nAMhAmQIAAMhAmQIAAMhAmQIAAMhAmQIAAMhAmQIAAMhAmQIAAMhAmQIAAMhwQNUBAKAJjjjiiOjt\n7a06BoAOGhwcfCYielJzlCkAKKG3t1cDAwNVxwDQQbafKjPHx3wAupbtS2wP2X7M9qVV5wHQTJQp\nAF3J9gmS/lzSqZJOlPRh2++sNhWAJqJMAehWx0l6KCJ+ExE7Jf1vSf+24kwAGogyBaBbDUn6Y9sz\nbB8q6WxJR1ecCUADcQA6gK4UERts/7WkuyS9LGmtpF2jZ2z3S+qXpLlz53Y8I4BmYM8UgK4VEddF\nxL+KiDMkPSfpn8Y8vioi+iKir6cneXY0gC7FnikAXcv2kRGxw/ZctY6XOq3qTACap6NlikXvgO5T\ndtG7inzX9gxJr0m6KCKerzoQgObJKlO2z5L0d5KmSPpGRHx5T/Msegd0n7KL3lUhIv646gwAmm+f\ny5TtKZKukrRY0hZJP7W9OiLWtyscANTF8PCwVq5cWXUM7IUVK1ZUHQFdIucA9FMlbYyITRHxqqRv\nSVranlgAAADNkFOm5kj65aj7W4ptAAAAXWPSl0aw3W97wPbAyMjIZL8cAABAR+WUqa363dWCjyq2\n/Q7WaQEAAPuznDL1U0nzbB9j+yBJ50la3Z5YAAAAzbDPZ/NFxE7bF0v6kVpLI1wfEY+1LRkAAEAD\nZK0zFRF3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+osdsSSfOKr361lobJQpkCgDe9cXWG\niHhV0u6rM4y2VK2V7aVWGVlUnCVZB8n8EXFfRPymuPsTtZamqZMyfwaS9F/VKrKvdDJcCWXy/7mk\nq3YvjFsst1MXZfKHpLcWt/9A0nAH8yVFxBpJezrpZ6mkm6LlJ5IOH3NG816jTAHAm8a7OsPYy+28\nMRMROyX9WtKMjqRLK5N/tAsl3TmpifZe8ncoPpY5OiJ+0MlgJZX5M/gjSX9k+//Y/ontPe1F6bQy\n+b8g6WO2t0i6Q9JfdCZa2+ztPydJVV1OBgBQIdsfk9Qn6b1VZ9kbtt8i6UpJH684So4D1PqI6Uy1\n9gyusf3uiHi+0lTlLZd0Q0R8xfZ7JP297ROKRX+7EnumAOBNZa7O8MaM7QPU+pjj2Y6kSyt1dQnb\nH5D0nySdExH/3KFsZaV+h8MknSDpx7Y3SzpN0uoaHYRe5s9gi6TVEfFaRDwp6Z/UKld1UCb/hWqt\npaeIeFDSwWqtEdgUbb8KC2UKAN5U5uoMo1e4P1fSvVGfBfuS+W2fJOnrahWpOh2rs9sef4eI+HVE\nHBERvRHRq9ZxX+dExEA1cX9Pmb9D/6jWXinZPkKtj/02dTLkHpTJ/wtJiyTJ9nFqlamRjqbMs1rS\nnxZn9Z0m6de5ixTzMR8AFCJip+2LJf1Ib16d4THb/0XSQESsVutyPH9ve6NaB7meV13i31Uy/xWS\npkn6h+K4+V9ExDmVhR6j5O9QWyXz/0jSB22vl7RL0mciohZ7N0vm/5Ska23/pVoHo3+8Rv9D8TtX\n1CiO61oh6UBJioivqXWc19mSNkr6jaQ/y37NGv3+AAAAjcPHfAAAABkoUwAAABkoUwAAABkoUwAA\nABkoUwAAABkoUwAAABkoUwAAABn+P0t70pYvEa2FAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x115e57320>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "i = random.choice(list(incorrect))\n",
    "\n",
    "pixels = mnist.test.images[i]\n",
    "truth  = mnist.test.labels[i]\n",
    "result = model.predict_on_batch(np.array([pixels]))[0]\n",
    "\n",
    "test_render(pixels, result, truth)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
